#include <cstdio>
#include <memory.h>

int f[ 2 ][ 2 ][ 2 ][ 2 ][ 3 ][ 3 ][ 3 ][ 3 ];
int g[ 2 ][ 2 ][ 2 ][ 3 ][ 3 ][ 3 ];
int n, m, time[ 9000 ], times, note[ 9000 ];
int a1[ 5 ], a2[ 5 ], h1[ 4 ], h2[ 7 ], v1[ 7 ], v2[ 7 ];
int max_score1, max_score2;

void init( )
{
    int i, t, pos;
    times = 2;
    time[ 0 ] = -1; time[ 1 ] = 0;
    max_score1 = max_score2 = 0;
    memset( note, 0, sizeof( note ) );
    while ( m-- )
    {
        scanf("%d%d", &t, &pos);
        pos--;
        if ( t - 2 > time[ times - 1 ] )
            time[ times++ ] = t - 2;
        if ( t - 1 > time[ times - 1 ] )
            time[ times++ ] = t - 1;
        if ( t > time[ times - 1 ] )
        {
            time[ times ] = t;
            note[ times++ ] |= 1 << pos;
        }
        if ( t == time[ times - 3 ] )
            note[ times - 3 ] |= 1 << pos;
        if ( t == time[ times - 2 ] )
            note[ times - 2 ] |= 1 << pos;
        if ( t == time[ times - 1 ] )
            note[ times - 1 ] |= 1 << pos;
        if ( t == time[ times - 1 ] && t + 1 <= n )
            time[ times++ ] = t + 1;
        if ( t + 1 == time[ times - 1 ] && t + 2 <= n )
            time[ times++ ] = t + 2;
    }
//    for ( i = 0; i < times; i++ )
//        printf("%d %d\n", time[ i ], note[ i ]);
    memset( f, 0, sizeof( f ) );
    memset( g, 0, sizeof( g ) );
    memset( v1, -1, sizeof( v1 ) );
    memset( v2, -1, sizeof( v2 ) );
}

void dfs1( int t )
{
    void dfs2( int );
    for ( a1[ 0 ] = 0; a1[ 0 ] < 2; a1[ 0 ]++ )
    {
        v1[ a1[ 0 ] ] = 0;
        for ( a1[ 1 ] = 0; a1[ 1 ] < 2; a1[ 1 ]++ )
        {
            if ( v1[ a1[ 1 ] + 1 ] != -1 )
                continue;
            v1[ a1[ 1 ] + 1 ] = 1;
            for ( a1[ 2 ] = 0; a1[ 2 ] < 2; a1[ 2 ]++ )
            {
                if ( v1[ a1[ 2 ] + 2 ] != -1 )
                    continue;
                v1[ a1[ 2 ] + 2 ] = 2;
                dfs2( t );
                v1[ a1[ 2 ] + 2 ] = -1;
            }
            v1[ a1[ 1 ] + 1 ] = -1;
        }
        v1[ a1[ 0 ] ] = -1;
    }
}

void dfs2( int t )
{
    void dfs3( int );
    for ( h1[ 0 ] = 0; h1[ 0 ] < 3; h1[ 0 ]++ )
    {
        if ( h1[ 0 ] == 1 )
            if ( !( 1 & note[ t - 1 ] ) )
                continue;
        if ( h1[ 0 ] == 2 )
            if ( !( 1 & note[ t ] ) )
                continue;
        for ( h1[ 1 ] = 0; h1[ 1 ] < 3; h1[ 1 ]++ )
        {
            if ( h1[ 1 ] == 1 )
                if ( !( 2 & note[ t - 1 ] ) )
                    continue;
            if ( h1[ 1 ] == 2 )
                if ( !( 2 & note[ t ] ) )
                    continue;
            for ( h1[ 2 ] = 0; h1[ 2 ] < 3; h1[ 2 ]++ )
            {
                if ( h1[ 2 ] == 1 )
                    if ( !( 4 & note[ t - 1 ] ) )
                        continue;
                if ( h1[ 2 ] == 2 )
                    if ( !( 4 & note[ t ] ) )
                        continue;
                for ( h1[ 3 ] = 0; h1[ 3 ] < 3; h1[ 3 ]++ )
                {
                    if ( h1[ 3 ] == 1 )
                        if ( !( 8 & note[ t - 1 ] ) )
                            continue;
                    if ( h1[ 3 ] == 2 )
                        if ( !( 8 & note[ t ] ) )
                            continue;
                    if ( h1[ 0 ] + h1[ 1 ] + h1[ 2 ] + h1[ 3 ] == 8 )
                        continue;
                    dfs3( t );
                }
            }
        }
    }
}

void dfs3( int t )
{
    void dfs4( int, int );
    h2[ 0 ] = h1[ 0 ] - 1; h2[ 0 ] >?= 0;
    for ( ; h2[ 0 ] < 3; h2[ 0 ]++ )
    {
        if ( h2[ 0 ] == 1 )
            if ( !( 1 & note[ t ] ) )
                continue;
        if ( h2[ 0 ] == 2 )
            if ( !( 1 & note[ t + 1 ] ) )
                continue;
        if ( h2[ 0 ] >= h1[ 0 ] && v1[ 0 ] == -1 && h2[ 0 ] )
            continue;
        h2[ 1 ] = h1[ 1 ] - 1; h2[ 1 ] >?= 0;
        for ( ; h2[ 1 ] < 3; h2[ 1 ]++ )
        {
            if ( h2[ 1 ] == 1 )
                if ( !( 2 & note[ t ] ) )
                    continue;
            if ( h2[ 1 ] == 2 )
                if ( !( 2 & note[ t + 1 ] ) )
                    continue;
            if ( h2[ 1 ] >= h1[ 1 ] && v1[ 1 ] == -1 && h2[ 1 ] )
                continue;
            h2[ 2 ] = h1[ 2 ] - 1; h2[ 2 ] >?= 0;
            for ( ; h2[ 2 ] < 3; h2[ 2 ]++ )
            {
                if ( h2[ 2 ] == 1 )
                    if ( !( 4 & note[ t ] ) )
                        continue;
                if ( h2[ 2 ] == 2 )
                    if ( !( 4 & note[ t + 1 ] ) )
                        continue;
                if ( h2[ 2 ] >= h1[ 2 ] && v1[ 2 ] == -1 && h2[ 2 ] )
                    continue;
                h2[ 3 ] = h1[ 3 ] - 1; h2[ 3 ] >?= 0;
                for ( ; h2[ 3 ] < 3; h2[ 3 ]++ )
                {
                    if ( h2[ 3 ] == 1 )
                        if ( !( 8 & note[ t ] ) )
                            continue;
                    if ( h2[ 3 ] == 2 )
                        if ( !( 8 & note[ t + 1 ] ) )
                            continue;
                    if ( h2[ 3 ] >= h1[ 3 ] && v1[ 3 ] == -1 && h2[ 3 ] )
                        continue;
                    dfs4( t, 0 );
                }
            }
        }
    }
}

void dfs4( int t, int pos )
{
    if ( pos < 3 )
    {
        int i;
        for ( i = 0; i < 4; i++ )
            if ( v1[ i ] == pos )
                break;
        if ( h2[ i ] >= h1[ i ] && h2[ i ] )
        {
            a2[ pos ] = i - pos;
            v2[ i ] = pos;
            dfs4( t, pos + 1 );
            v2[ i ] = -1;
        }
        else
        {
            for ( a2[ pos ] = 0; a2[ pos ] < 2; a2[ pos ]++ )
            {
                if ( v2[ a2[ pos ] + pos ] != -1 || ( h2[ a2[ pos ] + pos ] >= h1[ a2[ pos ] + pos ] && h2[ a2[ pos ] + pos ] != 0 ) )
                    continue;
                v2[ a2[ pos ] + pos ] = pos;
                dfs4( t, pos + 1 );
                v2[ a2[ pos ] + pos ] = -1;
            }
        }
    }
    else
    {
        int i, sum = 0, p2 = t & 1, p1 = p2 ^ 1;
        for ( i = 0; i < 3; i++ )
            if ( a1[ i ] == a2[ i ] )
            {
                if ( h2[ a2[ i ] + i ] == 0 && h1[ a2[ i ] + i ] == 0 && ( ( 1 << ( a2[ i ] + i ) ) & note[ t - 1 ] ) )
                    sum += 5;
                if ( h2[ a2[ i ] + i ] == 1 && h1[ a2[ i ] + i ] <= 1 )
                    sum += 10;
                if ( h2[ a2[ i ] + i ] == 2 )
                    sum += 5;
            }
        f[ p2 ][ a2[ 0 ] ][ a2[ 1 ] ][ a2[ 2 ] ][ h2[ 0 ] ][ h2[ 1 ] ][ h2[ 2 ] ][ h2[ 3 ] ] >?= 
            f[ p1 ][ a1[ 0 ] ][ a1[ 1 ] ][ a1[ 2 ] ][ h1[ 0 ] ][ h1[ 1 ] ][ h1[ 2 ] ][ h1[ 3 ] ] + sum;
        max_score1 >?= f[ p2 ][ a2[ 0 ] ][ a2[ 1 ] ][ a2[ 2 ] ][ h2[ 0 ] ][ h2[ 1 ] ][ h2[ 2 ] ][ h2[ 3 ] ];
    }
}

void dfs1_2( int t )
{
    void dfs2_2( int );
    for ( a1[ 0 ] = 0; a1[ 0 ] < 2; a1[ 0 ]++ )
    {
        v1[ a1[ 0 ] ] = 0;
        for ( a1[ 1 ] = 0; a1[ 1 ] < 2; a1[ 1 ]++ )
        {
            if ( v1[ a1[ 1 ] + 1 ] != -1 )
                continue;
            v1[ a1[ 1 ] + 1 ] = 1;
            dfs2_2( t );
            v1[ a1[ 1 ] + 1 ] = -1;
        }
        v1[ a1[ 0 ] ] = -1;
    }
}

void dfs2_2( int t )
{
    void dfs3_2( int );
    for ( h1[ 0 ] = 0; h1[ 0 ] < 3; h1[ 0 ]++ )
    {
        if ( h1[ 0 ] == 1 )
            if ( !( 16 & note[ t - 1 ] ) )
                continue;
        if ( h1[ 0 ] == 2 )
            if ( !( 16 & note[ t ] ) )
                continue;
        for ( h1[ 1 ] = 0; h1[ 1 ] < 3; h1[ 1 ]++ )
        {
            if ( h1[ 1 ] == 1 )
                if ( !( 32 & note[ t - 1 ] ) )
                    continue;
            if ( h1[ 1 ] == 2 )
                if ( !( 32 & note[ t ] ) )
                    continue;
            for ( h1[ 2 ] = 0; h1[ 2 ] < 3; h1[ 2 ]++ )
            {
                if ( h1[ 2 ] == 1 )
                    if ( !( 64 & note[ t - 1 ] ) )
                        continue;
                if ( h1[ 2 ] == 2 )
                    if ( !( 64 & note[ t ] ) )
                        continue;
                if ( h1[ 0 ] + h1[ 1 ] + h1[ 2 ] == 8 )
                    continue;
                dfs3_2( t );
            }
        }
    }
}

void dfs3_2( int t )
{
    void dfs4_2( int, int );
    h2[ 0 ] = h1[ 0 ] - 1; h2[ 0 ] >?= 0;
    for ( ; h2[ 0 ] < 3; h2[ 0 ]++ )
    {
        if ( h2[ 0 ] == 1 )
            if ( !( 16 & note[ t ] ) )
                continue;
        if ( h2[ 0 ] == 2 )
            if ( !( 16 & note[ t + 1 ] ) )
                continue;
        if ( h2[ 0 ] >= h1[ 0 ] && v1[ 0 ] == -1 && h2[ 0 ] )
            continue;
        h2[ 1 ] = h1[ 1 ] - 1; h2[ 1 ] >?= 0;
        for ( ; h2[ 1 ] < 3; h2[ 1 ]++ )
        {
            if ( h2[ 1 ] == 1 )
                if ( !( 32 & note[ t ] ) )
                    continue;
            if ( h2[ 1 ] == 2 )
                if ( !( 32 & note[ t + 1 ] ) )
                    continue;
            if ( h2[ 1 ] >= h1[ 1 ] && v1[ 1 ] == -1 && h2[ 1 ] )
                continue;
            h2[ 2 ] = h1[ 2 ] - 1; h2[ 2 ] >?= 0;
            for ( ; h2[ 2 ] < 3; h2[ 2 ]++ )
            {
                if ( h2[ 2 ] == 1 )
                    if ( !( 64 & note[ t ] ) )
                        continue;
                if ( h2[ 2 ] == 2 )
                    if ( !( 64 & note[ t + 1 ] ) )
                        continue;
                if ( h2[ 2 ] >= h1[ 2 ] && v1[ 2 ] == -1 && h2[ 2 ] )
                    continue;
                dfs4_2( t, 0 );
            }
        }
    }
}

void dfs4_2( int t, int pos )
{
    if ( pos < 2 )
    {
        int i;
        for ( i = 0; i < 3; i++ )
            if ( v1[ i ] == pos )
                break;
        if ( h2[ i ] >= h1[ i ] && h2[ i ] )
        {
            a2[ pos ] = i - pos;
            v2[ i ] = pos;
            dfs4_2( t, pos + 1 );
            v2[ i ] = -1;
        }
        else
        {
            for ( a2[ pos ] = 0; a2[ pos ] < 2; a2[ pos ]++ )
            {
                if ( v2[ a2[ pos ] + pos ] != -1 || ( h2[ a2[ pos ] + pos ] >= h1[ a2[ pos ] + pos ] && h2[ a2[ pos ] + pos ] != 0 ) )
                    continue;
                v2[ a2[ pos ] + pos ] = pos;
                dfs4_2( t, pos + 1 );
                v2[ a2[ pos ] + pos ] = -1;
            }
        }
    }
    else
    {
        int i, sum = 0, p2 = t & 1, p1 = p2 ^ 1;
        for ( i = 0; i < 2; i++ )
            if ( a1[ i ] == a2[ i ] )
            {
                if ( h2[ a2[ i ] + i ] == 0 && h1[ a2[ i ] + i ] == 0 && ( ( 1 << ( a2[ i ] + i + 4 ) ) & note[ t - 1 ] ) )
                    sum += 5;
                if ( h2[ a2[ i ] + i ] == 1 && h1[ a2[ i ] + i ] <= 1 )
                    sum += 10;
                if ( h2[ a2[ i ] + i ] == 2 )
                    sum += 5;
            }
        g[ p2 ][ a2[ 0 ] ][ a2[ 1 ] ][ h2[ 0 ] ][ h2[ 1 ] ][ h2[ 2 ] ] >?= 
            g[ p1 ][ a1[ 0 ] ][ a1[ 1 ] ][ h1[ 0 ] ][ h1[ 1 ] ][ h1[ 2 ] ] + sum;
        max_score2 >?= g[ p2 ][ a2[ 0 ] ][ a2[ 1 ] ][ h2[ 0 ] ][ h2[ 1 ] ][ h2[ 2 ] ];
    }
}

void work( )
{
    int i;
    for ( i = 1; i < times; i++ )
    {
        memset( f[ i & 1 ], 0, sizeof( f[ i & 1 ] ) );
        memset( g[ i & 1 ], 0, sizeof( g[ i & 1 ] ) );
        dfs1( i );
        dfs1_2( i );
    }
    printf("%d\n", max_score1 + max_score2);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
